package com.nuoniu.sibanyun.controller.erp;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpVoucherApproval;
import com.nuoniu.sibanyun.service.erp.IErpVoucherApprovalService;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 单据审核表 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-11-05
 */
@RestController
@RequestMapping("/erp/voucherApproval")
@Api(tags = "单据审核")
public class ErpVoucherApprovalController extends BaseController {

    @Autowired
    private IErpVoucherApprovalService voucherApprovalService;

    /**
     * 查询单据审核列表
     * @author 小啊刚
     * @date 2020-11-05
     */
    @GetMapping("list")
    public HttpResult list() {
        ErpVoucherApproval approval = new ErpVoucherApproval();
        approval.setCompanyId(UserThreadLocal.get().getCompanyId());
        QueryWrapper<ErpVoucherApproval> queryWrapper = new QueryWrapper<>(approval);
        return HttpResult.ok(voucherApprovalService.list(queryWrapper));
    }

    /**
     * 保存单据审核
     * @author 小啊刚
     * @date 2020-11-05
     */
    @PostMapping("save")
    public HttpResult save(@RequestBody ErpVoucherApproval approval) {
        if(approval.getId() == null) {
            approval.setCompanyId(UserThreadLocal.get().getCompanyId());
            approval.setCreateUserId(UserThreadLocal.get().getUserId());
        }
        voucherApprovalService.save(approval);
        return HttpResult.ok();
    }
}
